package com.huixi.service.impl;


import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.huixi.common.pojo.EasyUITreeNode;
import com.huixi.entity.ItemCat;
import com.huixi.service.ItemCatService;
import com.huixi.service.mapper.ItemCatMapper;

/**
 * <p>
 * 商品类目 服务实现类
 * </p>
 *
 * @author auto generator
 * @since 2019-05-27
 */
@Service("itemCatService")
public class ItemCatServiceImpl extends ServiceImpl<ItemCatMapper, ItemCat> implements ItemCatService {

	@Autowired
	private ItemCatMapper itemCatMapper;
	
	@Override
	public List<EasyUITreeNode> getItemCatList(long parentId) {
		//根据parentId查询子节点列表
		ItemCat itemCatInit = new ItemCat();
		//设置查询条件
		itemCatInit.setParentId(parentId);
		QueryWrapper<ItemCat> queryWrapper = new QueryWrapper<ItemCat>(itemCatInit);
		//执行查询
		List<ItemCat> list = itemCatMapper.selectList(queryWrapper);
		//创建返回结果List
		List<EasyUITreeNode> resultList = new ArrayList<EasyUITreeNode>();
		//把列表转换成EasyUITreeNode列表
		for(ItemCat itemCat :list) {
			EasyUITreeNode node = new EasyUITreeNode();
			//设置属性
			node.setId(itemCat.getId());
			node.setText(itemCat.getName());
			node.setState(itemCat.getIsParent()!=1?"closed":"open");
			//添加到结果列表
			resultList.add(node);
		}
		//返回结果
		return resultList;
	}
}
